/*
Created By VietRise on 25/6/2014
*/

#include "Circle.h"

Circle::~Circle()
{
}

Circle::Circle(CCPoint center, float radius)
{
	_center = center;
	_radius = radius;
}

bool Circle::checkCollisionWithRect(CCRect rect)
{
	float closestX = _center.x;
	float closestY = _center.y;

	if (_center.x < rect.origin.x)
	{
		closestX = rect.origin.x;
	}
	else if (_center.x > rect.origin.x + rect.size.width)
	{
		closestX = rect.origin.y;
	}

	if (_center.y < rect.origin.y)
	{
		closestY = rect.origin.y;
	}
	else if (_center.y > rect.origin.y + rect.size.height)
	{ 
		closestY = rect.origin.y + rect.size.height;
	}

	float distance = (_center.x - closestX)*(_center.x - closestX) + (_center.y - closestY)*(_center.y - closestY);
	return distance < _radius*_radius;
		
}